package service;

import dao.UniversityDao;
import domain.University;
import exception.BysjException;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class UniversityService implements UniversityServiceInterface{
    private static final UniversityDao universityDao = UniversityDao.getInstance();
    private static final UniversityService universityService = new UniversityService();
    //将唯一构造器设置成私有，阻止在本类外生成本类的对象
    private UniversityService(){
    }
    public static UniversityService getInstance(){
        return universityService;
    }
    public Collection<University> findAll(List<Condition> conditionList, Pagination pagination)throws SQLException , BysjException {
        Connection connection = JdbcHelper.getConn();
        Collection<University> teachers = universityDao.findAll(connection,conditionList,pagination);
        JdbcHelper.close(connection);
        return teachers;
    }
    public boolean add(University teacher)throws SQLException ,BysjException{
        Connection connection = JdbcHelper.getConn();
        boolean added = universityDao.add(connection,teacher);
        JdbcHelper.close(connection);
        return added;
    }
    public University find(int id)throws SQLException {
        University university = UniversityDao.getInstance().find(id);
        return university;
    }
    public boolean delete(int id)throws SQLException ,BysjException{
        boolean added = universityDao.delete(id);
        return added;
    }
    public boolean update(University teacher)throws SQLException ,BysjException{
        Connection connection = JdbcHelper.getConn();
        boolean added = universityDao.update(connection,teacher);
        JdbcHelper.close(connection);
        return added;
    }
}